/*********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  get_sms.h
 *    Description:  This file is used for function declarations.
 *                 
 *        Version:  1.0.0(05/1/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "05/1/2022  01:33:25 AM"
 *                 
 ********************************************************************************/



#ifndef _GET_SMS_H_
#define _GET_SMS_H_


#include <stdio.h>
#include <iconv.h>
#include <ctype.h>
#include "main.h"
#include "serial_init.h"
#include "sms_pdu.h"


/*--------------------------------------------------------------
 *   description:   Character stream byte stream
 *          args:   $source:    Character stream buffer address
 *                  $dest  :    Byte stream buffer address
 *                  $source_len:Character stream buffer length
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int str_to_hex(char *source, char *dest, int source_len);


/*--------------------------------------------------------------
 *   description:   Unicode encoding to UTF8 encoding
 *          args:   $unic_buf:    Unicode encoding buffer address
 *                  $unic_len:    Unicode encoding buffer length
 *                  $utf8_buf:    UTF8 Encoding buffer address
 *                  $utf8_len:    UTF8 Encoding buffer length
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int unicode_to_utf8(char *unic_buf,size_t unic_len,char *utf8_buf,size_t utf8_len);


/*--------------------------------------------------------------
 *   description:   Used for Text format decoding
 *          args:   $source:        Character stream buffer address
 *                  $dest:          Destination buffer address
 *                  $source_len:    Character stream length
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int text_decod(char *source, char *dest, int source_len);


/*--------------------------------------------------------------
 *   description:   This parameter is used to calculate the PDU 
 *                  center number, source number, and data length
 *          args:   $ptr:        Character stream buffer address
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int calculate_len(char *ptr);

/*--------------------------------------------------------------
 *   description:   Get information about a specified number
 *          args:   $ttyusb_ctx:    Serial port property context
 *                  $sms_buf:       The address of the buffer where 
 *                  the returned information is stored
 *                  $sms_buf_len:   sms_buf length
 *                  $target_number: Destination number buffer address
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int get_specified_sms(ttyusb_ctx_t *ttyusb_ctx, char *sms_buf, int sms_buf_len, char *target_number);


/*--------------------------------------------------------------
 *   description:   Get information about a specified number
 *          args:   $ttyusb_ctx:    Serial port property context
 *                  $sms_buf:       The address of the buffer where 
 *                  the returned information is stored
 *                  $sms_buf_len:   sms_buf length
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int get_all_sms(ttyusb_ctx_t *ttyusb_ctx, char *sms_buf, int sms_buf_len);


/*--------------------------------------------------------------
 *   description:   Decoding by 7bit encoding
 *          args:   $source:    Source buffer address
 *                  $dest  :    The target buffer address
 *                  $source_len:Source buffer length
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int decode7bit(const unsigned char* source, char* dest, int source_len);


/*--------------------------------------------------------------
 *   description:   Get information about a specified number
 *          args:   $ttyusb_ctx:    Serial port property context
 *                  $sms_buf:       The address of the buffer where 
 *                  $target_number: Destination number buffer address
 *  return value:   <0: failure,    =0:ok 
 *--------------------------------------------------------------*/
int delete_sms(ttyusb_ctx_t *ttyusb_ctx, char *target_number);

#endif